﻿<?=$this->load->view('include_header',null)?>
	<div id="top-panel">
		<div id="panel">
			<ul>
				<li class="current"><a href="<?=site_url('archive/idcard/'.$id)?>" class="report"><?=(empty($id))?"录入新":"编辑"?>客户基本信息</a></li>
				
			</ul>
		</div>
	</div>
	<div id="wrapper">
		<div id="content">
			<div id="box">
			<form id="form" method="POST" action="<?=site_url('archive/idcard_update')?>">
			<fieldset>
			<legend>身份证信息 National ID Card</legend>
			<label>姓氏<br>Surnames:</label><input type="text" name="surname" value="<?=@$info->surname?>" /> <br /><br>
			<label>名字<br>Given names:</label><input type="text" name="firstname" value="<?=@$info->firstname?>" /> <br /> <br>
			<label>身份证号码<br>National ID Number:</label><input type="text" name="national_id" value="<?=@$info->national_id?>" style="width:200px" /> <br /><br>
			<label>性别<br>Sex:</label><input type="radio" name="sex" value="1" <?= (@$info->sex==1)?'checked':''?> />男 / Male <input type="radio" name="sex" value="2" <?= (@$info->sex==2)?'checked':''?> /> 女 / Female <br /> <br>
			<label>民族<br>Ethnic Group:</label>
            <!--<input type="text" name="nation" id="nation" value="<?=@$info->nation?>" style='background:#FFFFC0'/>-->
            <select name="nation" style='background:#FFFFC0'/>
                <?foreach($ethnic as $row) {
                    $is_selected = (@$info->nation==$row->en_name) ? "selected" : "";
                    echo "<option value='".$row->en_name."' $is_selected>". substr($row->en_name, 0, 1) ."-".$row->cn_name."-[".$row->en_name."]</option>";
                }?>
            </select>
            <br /> <br>
			<label>出生日期<br>Date of Birth:</label>
				<select name="birth_y"><?php for($i=2012;$i>1940;$i--) echo "<option value='$i'".((@$info->birth_y==$i)?"selected":"").">$i</option>"; ?></select>年 - 
				<select name="birth_m"><?php for($i=1;$i<=12;$i++) echo "<option value='$i'".((@$info->birth_m==$i)?"selected":"").">$i</option>"; ?></select>月 - 
				<select name="birth_d"><?php for($i=1;$i<=31;$i++) echo "<option value='$i'".((@$info->birth_d==$i)?"selected":"").">$i</option>"; ?></select>日 <br /><br>
			<label>家庭住址<br>Address:</label><input type="text" name="home_address" value="<?=@$info->home_address?>" style="width:500px"/> <br /><br>
			<label>有效期起<br>Issuance Date:</label><input type="text" name="issuing_date_from" id="issuing_date_from" value="<?=@$info->issuing_date_from?>" onchange="check_date_rules()"/> <br /> <br>
			<label>有效期止<br>Expiration Date:</label><input type="text" name="issuing_date_to" id="issuing_date_to" value="<?=@$info->issuing_date_to?>" onchange="check_date_rules()"/> <br /> <br>
			<label>发证机关<br>Issued By:</label><input type="text" name="issuing_by" value="<?=@$info->issuing_by?>"/> <br /><br>
			<input type="hidden" name="id" value="<?=$id?>" />
			<input id="button1" type="submit" value="提交信息 Continue" onclick="return check_date_rules()"/>
			<input id="button2" type="reset" value="重置 Cancel" />
			</fieldset>
			</form>
			</div>

		</div>
        
		<script type="text/javascript" src="js/jquery.autocomplete.pack.js"></script>
        <link type="text/css" rel="stylesheet" href="css/jquery.autocomplete.css"/>
        
		<?=$this->load->view('include_sidebar',array('id'=>$id,'forms'=>$forms))?>
	</div>

	<script type="text/javascript">
    function check_date_rules() {
        var birth_date = $('select[name=birth_d]').val()+"/"+$('select[name=birth_m]').val()+"/"+$('select[name=birth_y]').val();
        if(convert_to_date(birth_date).getTime() > new Date().getTime()) {
            alert('[出生日期]不能大于当前日期！');
            return false;
        }
        if(convert_to_date($('#issuing_date_from').val()).getTime() > new Date().getTime()) {
            alert('[有效期起]不能大于当前日期！');
            return false;
        } 
        if(convert_to_date($('#issuing_date_from').val()).getTime() > convert_to_date($('#issuing_date_to').val()).getTime()) {
            alert('[有效期起]不能大于[有效期止]！');
            return false;
        }           
        return true; 
    }
    
    
	$().ready(function() {
	  $("#form").validate({
		rules: {
			surname:{
			 required:true
			},
			firstname:{
			 required:true
			},
			national_id:{
			 required:true,
			 rangelength:[15,18]
			},
			sex:{
			 required:true
			}
		}
	  });
	  
		$.datepicker.setDefaults(
			{
			dateFormat: 'dd/mm/yy',
			changeMonth: true,
			changeYear: true,
			showOn: "both",
			buttonImage: "images/calendar.gif",
			buttonImageOnly: true
			}
		);
		
		$("#issuing_date_from").datepicker();
		$("#issuing_date_to").datepicker();
        
        $("#nation").autocomplete("<?=base_url()?>user/quick_search_ethnic", {
            minChars: 0,
            width: 500,
            matchContains: "word",
            autoFill: false,
            formatItem: function(row, i, max) {
                var arr = (row+"").split(",");
                return i + "/" + max + ": " + arr[1] + '['+ arr[2] +']';
            },
            formatMatch: function(row, i, max) {
                return row;
            },
            formatResult: function(row) {
                var arr = (row+"").split(",");
                return arr[2];
            }
        });

        $("#nation").result(function(event, data, formatted){
            var arr = (formatted+"").split(",");
        });       
	});
	</script>
	
<?=$this->load->view('include_footer',null)?>
